﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using WPF_MVVM_PathSearchUtil.Models;

namespace WPF_MVVM_PathSearchUtil.util
{
    public class FileListConverter : IValueConverter
    {
        /// <summary>
        /// 修改binding的画面数据格式
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return null;
            }

            if (parameter == null)
            {
                throw new ArgumentNullException(nameof(parameter));
            }

            string format = parameter.ToString();
            FileInfoModel fileInfo = value as FileInfoModel;

            switch (format)
            {
                case "FileSize":
                    return $"{fileInfo.FileSize} KB";
                case "FileDate":
                    return $"{fileInfo.FileDate.ToString("yyyy-MM-dd HH:mm:ss")}";
                default:
                    return null;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
